﻿#ifndef GRID_H
#define GRID_H

#include "cell.h"
#include <cmath>
#include <QGraphicsScene>
#include <QGraphicsTextItem>
#include <QMap>
#include <QLineEdit>
#include <QGraphicsSceneMouseEvent>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QStringList>
#include <QTextStream>
#include <QFileDialog>
#include <QDialog>
#include <QInputDialog>
#include <QMessageBox>
#include <QLabel>
#include <QHBoxLayout>

class Screen;
class PlayScreen;
class EditScreen;
//*******************************************************************//
//main
//*******************************************************************//
class Grid : public QGraphicsScene
{
    Q_OBJECT
public:
    explicit Grid(Screen* parent);
    void Clean();
    void Save(int, QString);
    void BreakTip(QString&);
    bool CheckMKDir(QString);

public:
    Screen* p;
    QMap<int, QString> Tips;
    QMap<int, Cell*> cells;
    QString gridname;
    QString draftname;
    bool isPlaying;

public slots:
    void Load(QString filename = "");

protected:
    void mousePressEvent(QGraphicsSceneMouseEvent *event);
};
//*******************************************************************//
//play
//*******************************************************************//
class PlayGrid : public Grid
{
    Q_OBJECT
public:
    PlayGrid(PlayScreen* parent);

public:
    PlayScreen* p;

public slots:
    void SaveGrid(bool type = false);
    void Result();
    void Quit();
    int Done(bool closing);
};
//*******************************************************************//
//edit
//*******************************************************************//
class EditGrid : public Grid
{
    Q_OBJECT
public:
    EditGrid(EditScreen* parent);

public:
    EditScreen* p;
    bool state;
    int startX;
    int startY;
    int R;
    int G;
    int B;
    QGraphicsLineItem* hLine;
    QGraphicsLineItem* vLine;

public:
    void showCell(int X, int Y);
    void updateTip(int X, int Y);

public slots:
    void updateTipSlot(QString);
    void deleteTipSlot(QString);
    void addTipSlot(int, int);
    void SaveGrid();
    void SaveDraft();

protected:
   void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);

};

#endif // GRID_H
